package com.hsogoo.collate.redis;

import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @Author huangsaigang
 * Created @2019/4/4.
 */
public class RedisClientImportSelector implements ImportSelector {

    private final String CLUSTER = "cluster";
    private final String SINGLE = "single";

    @Override
    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        Class<?> annotationType = EnableRedisClient.class;
        AnnotationAttributes attributes = AnnotationAttributes.fromMap(annotationMetadata.getAnnotationAttributes(
                annotationType.getName(), false));
        String mode = attributes.getString("mode");
        if(CLUSTER.equals(mode)){
            return new String[]{RedisClusterConfiguration.class.getName()};
        }else if(SINGLE.equals(mode)){
            return new String[]{RedisSingleConfiguration.class.getName()};
        }
        return null;
    }
}
